package com.heatup.apt.common.dao;

import com.heatup.apt.model.coupon.ActivityUser;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

@Component
public interface ActivityUserMapper {
    @Delete({
        "delete from activity_user",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into activity_user (activity_id, ",
        "userid, invite_userid, ",
        "create_time, create_by,is_geted_coupon)",
        "values ( #{activityId,jdbcType=INTEGER}, ",
        "#{userid,jdbcType=INTEGER}, #{inviteUserid,jdbcType=INTEGER}, ",
        "#{createTime,jdbcType=TIMESTAMP}, #{createBy,jdbcType=VARCHAR}),#{isGetedCoupon,jdbcType=INTEGER})"
    })
    int insert(ActivityUser record);

    int insertSelective(ActivityUser record);

    @Select({
        "select",
        "id, activity_id, userid, invite_userid, create_time, create_by,is_geted_coupon",
        "from activity_user",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @ResultMap("BaseResultMap")
    ActivityUser selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(ActivityUser record);

    @Update({
        "update activity_user",
        "set activity_id = #{activityId,jdbcType=INTEGER},",
          "userid = #{userid,jdbcType=INTEGER},",
          "invite_userid = #{inviteUserid,jdbcType=INTEGER},",
          "create_time = #{createTime,jdbcType=TIMESTAMP},",
          "create_by = #{createBy,jdbcType=VARCHAR},",
          "is_geted_coupon = #{isGetedCoupon,jdbcType=INTEGER}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(ActivityUser record);
    
    List<ActivityUser> queryActivityUser(Map<String,Object> map);
    
    /**
     * 插入不重复的数据
     * 主要用于邀请好友
     * @param activityUser
     * @return
     */
    Integer addActivityUserNotRepeat(@Param("activityUser")ActivityUser activityUser);
}